<?php

namespace App\Helper;

class View
{
    /**
     * 用户主信息
     * @param $user
     * @return string
     */
    public static function user($user){
        $user = collect($user)->toArray();
        $avatar = cdn_url($user['avatar']);
        $avatarHtml = $avatar?'<img data-action="preview-img" src="'.$avatar.'" style="max-width:50px;max-height:50px;cursor:pointer" class="img img-thumbnail">':"";
        return <<<HTML
<div class="flex-row">
    {$avatarHtml}
    <div style="margin-left: 3px">
        <p class="mb-0">昵称: {$user['nickname']}</p>
        <p class="mb-0" style="margin: 2px">姓名: {$user['name']}</p>
        <p class="mb-0">手机号: {$user['mobile']}</p>
    </div>
</div>
HTML;
    }

    /**
     * 用户其他信息
     * @param $user
     * @return string
     */
    public static function info($user){
        $user = collect($user)->toArray();
        $names = [];
        if ($user['partition']){
            $names[] = $user['partition']['name'];
        }
        if ($user['area']){
            $names[] = $user['area']['name'];
        }
        if ($user['school']){
            $names[] = $user['school']['name'];
        }
        return $names? implode("/",$names) :"";
    }

}
